namespace Scap.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class db : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ScapConfigurations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 100),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapMonitorConfigurations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Interval = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapEmailConfigurations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Host = c.String(nullable: false),
                        Port = c.Int(nullable: false),
                        Ssl = c.Boolean(nullable: false),
                        Username = c.String(nullable: false),
                        Password = c.String(nullable: false),
                        Email = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapLocationAddresses",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        CityId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapLocationCities", t => t.CityId, cascadeDelete: true)
                .Index(t => t.CityId);
            
            CreateTable(
                "dbo.ScapLocationCities",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        ProvinceId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapLocationProvinces", t => t.ProvinceId, cascadeDelete: true)
                .Index(t => t.ProvinceId);
            
            CreateTable(
                "dbo.ScapLocationProvinces",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        CountryId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapLocationCountries", t => t.CountryId, cascadeDelete: true)
                .Index(t => t.CountryId);
            
            CreateTable(
                "dbo.ScapLocationCountries",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapCompanies",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Description = c.String(),
                        AddressId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapLocationAddresses", t => t.AddressId)
                .Index(t => t.AddressId);
            
            CreateTable(
                "dbo.ScapDepartments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Description = c.String(),
                        TypeId = c.Int(nullable: false),
                        AddressId = c.Int(),
                        ParentDepartmentId = c.Int(),
                        CompanyId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapDepartmentTypes", t => t.TypeId, cascadeDelete: true)
                .ForeignKey("dbo.ScapLocationAddresses", t => t.AddressId)
                .ForeignKey("dbo.ScapDepartments", t => t.ParentDepartmentId)
                .ForeignKey("dbo.ScapCompanies", t => t.CompanyId, cascadeDelete: true)
                .Index(t => t.TypeId)
                .Index(t => t.AddressId)
                .Index(t => t.ParentDepartmentId)
                .Index(t => t.CompanyId);
            
            CreateTable(
                "dbo.ScapDepartmentTypes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Description = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapDevices",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        TimeZone = c.Int(nullable: false),
                        SerialNumber = c.String(),
                        Connection = c.Int(nullable: false),
                        IpAddress = c.String(nullable: false),
                        IpPort = c.Int(nullable: false),
                        CommunicationKey = c.String(),
                        Status = c.Int(nullable: false),
                        StatusMessage = c.String(),
                        DepartmentId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapDepartments", t => t.DepartmentId, cascadeDelete: true)
                .Index(t => t.DepartmentId);
            
            CreateTable(
                "dbo.ScapEmployees",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Identification = c.String(nullable: false),
                        FirstName = c.String(nullable: false),
                        LastName = c.String(nullable: false),
                        Genre = c.String(),
                        SocialSecurityNumber = c.String(),
                        Birthday = c.DateTime(nullable: false),
                        OriginCityId = c.Int(),
                        ResidenceCityId = c.Int(),
                        HomeAddress = c.String(),
                        BusinessAddress = c.String(),
                        PostalCode = c.String(),
                        HomePhone = c.String(),
                        BusinessPhone = c.String(),
                        CellPhone = c.String(maxLength: 20),
                        Email = c.String(nullable: false, maxLength: 100),
                        Image = c.String(),
                        User_UserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.UserProfile", t => t.User_UserId)
                .ForeignKey("dbo.ScapLocationCities", t => t.OriginCityId)
                .ForeignKey("dbo.ScapLocationCities", t => t.ResidenceCityId)
                .Index(t => t.User_UserId)
                .Index(t => t.OriginCityId)
                .Index(t => t.ResidenceCityId);
            
            CreateTable(
                "dbo.UserProfile",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(),
                    })
                .PrimaryKey(t => t.UserId);
            
            CreateTable(
                "dbo.ScapEmployeeEnrolls",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Type = c.Int(nullable: false),
                        Index = c.Int(nullable: false),
                        Data = c.Binary(),
                        EmployeeId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapEmployees", t => t.EmployeeId, cascadeDelete: true)
                .Index(t => t.EmployeeId);
            
            CreateTable(
                "dbo.ScapEmployeeStatus",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapEmployeeTypes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapEmployeeRoles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        ManageEmployees = c.Boolean(nullable: false),
                        ManageDevices = c.Boolean(nullable: false),
                        ManageServer = c.Boolean(nullable: false),
                        ManageReports = c.Boolean(nullable: false),
                        ManageConfigurations = c.Boolean(nullable: false),
                        NotifyOnDeviceDisconnect = c.Boolean(nullable: false),
                        NotifyOnEmployeeTransfer = c.Boolean(nullable: false),
                        NotifyOnEmployeeTransferEnds = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapDepartmentEmployees",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DepartmentId = c.Int(nullable: false),
                        EmployeeId = c.Int(nullable: false),
                        RoleId = c.Int(nullable: false),
                        EmployeeTypeId = c.Int(nullable: false),
                        EmploymentStatusId = c.Int(nullable: false),
                        StartDate = c.DateTime(nullable: false),
                        EndDate = c.DateTime(),
                        IsEnabled = c.Boolean(nullable: false),
                        Comments = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapDepartments", t => t.DepartmentId, cascadeDelete: true)
                .ForeignKey("dbo.ScapEmployees", t => t.EmployeeId, cascadeDelete: true)
                .ForeignKey("dbo.ScapEmployeeRoles", t => t.RoleId, cascadeDelete: true)
                .ForeignKey("dbo.ScapEmployeeTypes", t => t.EmployeeTypeId, cascadeDelete: true)
                .ForeignKey("dbo.ScapEmployeeStatus", t => t.EmploymentStatusId, cascadeDelete: true)
                .Index(t => t.DepartmentId)
                .Index(t => t.EmployeeId)
                .Index(t => t.RoleId)
                .Index(t => t.EmployeeTypeId)
                .Index(t => t.EmploymentStatusId);
            
            CreateTable(
                "dbo.ScapSchedules",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Description = c.String(),
                        IsEnabled = c.Boolean(nullable: false),
                        CheckInRequired = c.Boolean(nullable: false),
                        StartDate = c.DateTime(nullable: false),
                        EndDate = c.DateTime(nullable: false),
                        CheckIn = c.DateTime(nullable: false),
                        CheckOut = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ScapEmployeeSchedules",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DepartmentEmployeeId = c.Int(nullable: false),
                        ScheduleId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapDepartmentEmployees", t => t.DepartmentEmployeeId, cascadeDelete: true)
                .ForeignKey("dbo.ScapSchedules", t => t.ScheduleId, cascadeDelete: true)
                .Index(t => t.DepartmentEmployeeId)
                .Index(t => t.ScheduleId);
            
            CreateTable(
                "dbo.ScapEmployeeAssistances",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        EmployeeId = c.Int(nullable: false),
                        CheckTime = c.DateTime(nullable: false),
                        Type = c.Int(nullable: false),
                        RawData = c.String(),
                        Comments = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ScapDepartmentEmployees", t => t.EmployeeId, cascadeDelete: true)
                .Index(t => t.EmployeeId);
            
            CreateTable(
                "dbo.ScapCommands",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Command = c.String(),
                        Progress = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.ScapEmployeeAssistances", new[] { "EmployeeId" });
            DropIndex("dbo.ScapEmployeeSchedules", new[] { "ScheduleId" });
            DropIndex("dbo.ScapEmployeeSchedules", new[] { "DepartmentEmployeeId" });
            DropIndex("dbo.ScapDepartmentEmployees", new[] { "EmploymentStatusId" });
            DropIndex("dbo.ScapDepartmentEmployees", new[] { "EmployeeTypeId" });
            DropIndex("dbo.ScapDepartmentEmployees", new[] { "RoleId" });
            DropIndex("dbo.ScapDepartmentEmployees", new[] { "EmployeeId" });
            DropIndex("dbo.ScapDepartmentEmployees", new[] { "DepartmentId" });
            DropIndex("dbo.ScapEmployeeEnrolls", new[] { "EmployeeId" });
            DropIndex("dbo.ScapEmployees", new[] { "ResidenceCityId" });
            DropIndex("dbo.ScapEmployees", new[] { "OriginCityId" });
            DropIndex("dbo.ScapEmployees", new[] { "User_UserId" });
            DropIndex("dbo.ScapDevices", new[] { "DepartmentId" });
            DropIndex("dbo.ScapDepartments", new[] { "CompanyId" });
            DropIndex("dbo.ScapDepartments", new[] { "ParentDepartmentId" });
            DropIndex("dbo.ScapDepartments", new[] { "AddressId" });
            DropIndex("dbo.ScapDepartments", new[] { "TypeId" });
            DropIndex("dbo.ScapCompanies", new[] { "AddressId" });
            DropIndex("dbo.ScapLocationProvinces", new[] { "CountryId" });
            DropIndex("dbo.ScapLocationCities", new[] { "ProvinceId" });
            DropIndex("dbo.ScapLocationAddresses", new[] { "CityId" });
            DropForeignKey("dbo.ScapEmployeeAssistances", "EmployeeId", "dbo.ScapDepartmentEmployees");
            DropForeignKey("dbo.ScapEmployeeSchedules", "ScheduleId", "dbo.ScapSchedules");
            DropForeignKey("dbo.ScapEmployeeSchedules", "DepartmentEmployeeId", "dbo.ScapDepartmentEmployees");
            DropForeignKey("dbo.ScapDepartmentEmployees", "EmploymentStatusId", "dbo.ScapEmployeeStatus");
            DropForeignKey("dbo.ScapDepartmentEmployees", "EmployeeTypeId", "dbo.ScapEmployeeTypes");
            DropForeignKey("dbo.ScapDepartmentEmployees", "RoleId", "dbo.ScapEmployeeRoles");
            DropForeignKey("dbo.ScapDepartmentEmployees", "EmployeeId", "dbo.ScapEmployees");
            DropForeignKey("dbo.ScapDepartmentEmployees", "DepartmentId", "dbo.ScapDepartments");
            DropForeignKey("dbo.ScapEmployeeEnrolls", "EmployeeId", "dbo.ScapEmployees");
            DropForeignKey("dbo.ScapEmployees", "ResidenceCityId", "dbo.ScapLocationCities");
            DropForeignKey("dbo.ScapEmployees", "OriginCityId", "dbo.ScapLocationCities");
            DropForeignKey("dbo.ScapEmployees", "User_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.ScapDevices", "DepartmentId", "dbo.ScapDepartments");
            DropForeignKey("dbo.ScapDepartments", "CompanyId", "dbo.ScapCompanies");
            DropForeignKey("dbo.ScapDepartments", "ParentDepartmentId", "dbo.ScapDepartments");
            DropForeignKey("dbo.ScapDepartments", "AddressId", "dbo.ScapLocationAddresses");
            DropForeignKey("dbo.ScapDepartments", "TypeId", "dbo.ScapDepartmentTypes");
            DropForeignKey("dbo.ScapCompanies", "AddressId", "dbo.ScapLocationAddresses");
            DropForeignKey("dbo.ScapLocationProvinces", "CountryId", "dbo.ScapLocationCountries");
            DropForeignKey("dbo.ScapLocationCities", "ProvinceId", "dbo.ScapLocationProvinces");
            DropForeignKey("dbo.ScapLocationAddresses", "CityId", "dbo.ScapLocationCities");
            DropTable("dbo.ScapCommands");
            DropTable("dbo.ScapEmployeeAssistances");
            DropTable("dbo.ScapEmployeeSchedules");
            DropTable("dbo.ScapSchedules");
            DropTable("dbo.ScapDepartmentEmployees");
            DropTable("dbo.ScapEmployeeRoles");
            DropTable("dbo.ScapEmployeeTypes");
            DropTable("dbo.ScapEmployeeStatus");
            DropTable("dbo.ScapEmployeeEnrolls");
            DropTable("dbo.UserProfile");
            DropTable("dbo.ScapEmployees");
            DropTable("dbo.ScapDevices");
            DropTable("dbo.ScapDepartmentTypes");
            DropTable("dbo.ScapDepartments");
            DropTable("dbo.ScapCompanies");
            DropTable("dbo.ScapLocationCountries");
            DropTable("dbo.ScapLocationProvinces");
            DropTable("dbo.ScapLocationCities");
            DropTable("dbo.ScapLocationAddresses");
            DropTable("dbo.ScapEmailConfigurations");
            DropTable("dbo.ScapMonitorConfigurations");
            DropTable("dbo.ScapConfigurations");
        }
    }
}
